<template>
  <div>
    <el-dialog title="修改备注" :visible.sync="dialogVisible" width="600px" @close="close">
      <el-form v-loading="loading" label-suffix="：" label-width="100px" size="small">
        <el-form-item label="备注">
          <el-input v-model.trim="remark" maxlength="30" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" round @click="hide">取 消</el-button>
        <el-button size="small" round type="primary" :disabled="loading" @click="sumbit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { modifyOrderRemark } from '../../api/record'
export default {
  data() {
    return {
      // 配置
      resolve: null,
      reject: null,
      dialogVisible: null,
      loading: false,
      // 数据
      detail: '',
      remark: ''
    }
  },
  methods: {
    open(detail) {
      this.detail = detail
      this.show()
      return new Promise((resolve, reject) => {
        this.resolve = resolve
        this.reject = reject
      })
    },

    show() {
      this.dialogVisible = true
    },

    close() {
      this.remark = ''
      this.loading = false
    },

    hide() {
      this.resolve = null
      this.reject = null
      this.dialogVisible = false
    },

    sumbit() {
      const params = {}
      params.orderNo = this.detail.orderNo
      params.remark = this.remark
      this.loading = true
      modifyOrderRemark(params)
        .then(res => {
          this.$notify({
            title: '成功',
            message: '更新备注成功',
            type: 'success',
            duration: 2000,
            offset: 40
          })
          this.resolve && this.resolve()
          this.hide()
        })
        .catch(err => {})
        .finally(() => {
          this.loading = false
        })
    }
  }
}
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
</style>
